package com.yx.frame.jdbc.pool;

import java.sql.Connection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class WebLogicPool implements Pool {
	private String name = null;
	private int maxQueryRowCountList = 50000;

	public WebLogicPool(String name, int maxQueryRowCountList) {
		this.name = name;
		this.maxQueryRowCountList = maxQueryRowCountList;
	}

	public int getMaxQueryRowCountList() {
		return this.maxQueryRowCountList;
	}

	public PConnection getConnection() throws Exception {
		DataSource tmpDS = null;
		Connection conn = null;
		try {
			Context ctx = new InitialContext();
			tmpDS = (DataSource) ctx.lookup(this.name);
			conn = tmpDS.getConnection();
		} catch (Exception e) {
			throw new Exception("Try to get weblogic connection[" + this.name + "]have a error:" + e);
		}
		PConnection pConnection = new PConnection(conn);
		return pConnection;
	}

	public int getMaxQueryRowCount() {
		return this.maxQueryRowCountList;
	}

	public String getName() {
		return this.name;
	}

	public boolean isFramePool() {
		return false;
	}

	@Override
	public ComboPooledDataSource getDataSource() {
		return null;
	}
}
